package com.interview.controller;

import com.interview.common.Result;
import com.interview.common.ResultMessage;
import com.interview.common.StatusCode;
import com.interview.entity.Examee;
import com.interview.entity.GroupInfo;
import com.interview.entity.SignedInfo;
import com.interview.entity.SignedStatics;
import com.interview.service.ExameeService;
import com.interview.service.GroupInfoService;
import com.interview.service.SignedInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("exameeSign")
public class SignController {
    @Autowired
    private SignedInfoService signedInfoService;
    @Autowired
    private ExameeService exameeService;
    @Autowired
    private GroupInfoService groupInfoService;

    @PostMapping("getExameeSignedList")
    public Result getExameeSignedList() {
        List<SignedInfo> allSignedExamee = signedInfoService.getAllSignedExamee();

        return new Result(true, StatusCode.OK, ResultMessage.QUERY_SUCCESS,allSignedExamee);
    }

    @PostMapping("validation")
    public Result sign(@RequestParam("idNumber")String idNumber) {
        Examee examee =exameeService.getExameeById(idNumber);
        if (examee == null) {
            return new Result(false, StatusCode.ERROR, ResultMessage.EXAMEE_NOT_EXIST,null);
        }else {
            SignedInfo signedExamee = signedInfoService.getSignedExamee(idNumber);

            if (signedExamee == null) {
                signedInfoService.sign(idNumber);
                return new Result(true, StatusCode.OK, ResultMessage.SIGN_SUCCESS, null);
            }else {
                return new Result(false, StatusCode.ERROR, ResultMessage.EXAMER_SIGNED,null);
            }

        }
    }


    @PostMapping("getSignedStatics")
    public Result getSignedStatics(){
        List<SignedStatics> signedStatics = signedInfoService.getSignedStaticsList();

        return new Result(true,StatusCode.OK,ResultMessage.QUERY_SUCCESS,signedStatics);

    }
}
